17. Quiz: Checking out the Docs (6-7)

Manipulating Arrays

Use the MDN Documentation to determine which of these methods would be best for reversing elements in this array:

var reverseMe = ["h", "e", "l", "l", "o"];
SOLUTION: reverse()

What would be the best array method to sort the elements in this array:

var sortMe = [2, 1, 10, 7, 6];
SOLUTION: sort()

Removing the first element

Consider the following array, removeFirstElement:

var removeFirstElement = ["a", "b", "c"];

Let's say that you want to modify (i.e., mutate) removeFirstElement by removing the first element within it. Which method(s) could you use?

SOLUTION:
  • shift()
  • splice()

Array to String

What method would be best for changing this array into a string?

var turnMeIntoAString = ["U", "d", "a", "c", "i", "t", "y"];
SOLUTION: join()

Have questions? Head to Knowledge for discussion with the Udacity Community.